package com.healthcloud.controller.modules.hospital;

import java.util.List;

import com.healthcloud.entity.MsgVo;
import com.healthcloud.utils.ApiRes;
import com.healthcloud.utils.PageParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.healthcloud.entity.WHospitalEntity;
import com.healthcloud.service.WHospitalService;


/**
 * 美康医院表
 * 
 */
@Controller
@RequestMapping("wHospital")
public class WHospitalController {
	@Autowired
	private WHospitalService wHospitalService;
	
    @ApiOperation("跳转列表页")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@RequiresPermissions("whospital:list")
	public String list(){
		return "bus/whospital/whospitalmgr";
	}

    @ApiOperation("医院列表")
	@RequiresPermissions("whospital:list")
	@RequestMapping(value = "/searchWHospital", method = RequestMethod.POST)
	@ResponseBody
    public MsgVo  searchWHospital(WHospitalEntity bean, @ModelAttribute("pageParam")PageParam pageParam){
        List<WHospitalEntity> list = wHospitalService.queryList(bean, pageParam);
        int count = wHospitalService.queryTotal(bean);
        return new MsgVo(list,count,count,pageParam.getsEcho());
    }
	
    @ApiOperation("跳转到新增页")
	@RequestMapping(value = "/tosave", method = RequestMethod.GET)
	@RequiresPermissions("whospital:save")
    public String toSave() {
        return "bus/whospital/addOrUpdatewhospital";
    }
    
    @ApiOperation("保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public ApiRes save(WHospitalEntity entity) {
        wHospitalService.save(entity);
        return ApiRes.SUCCESS;
    }
	
    @ApiOperation("跳转修改页")
	@RequestMapping(value = "/toupdate", method = RequestMethod.GET)
    @RequiresPermissions("whospital:update")
    public String toUpdate(@Param("id") Integer id, Model model) {

        WHospitalEntity entity = wHospitalService.queryObject(id);
        model.addAttribute("entity", entity);

        return "bus/whospital/addOrUpdatewhospital";
    }
	
    @ApiOperation("修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public ApiRes update(WHospitalEntity entity) {
        wHospitalService.update(entity);
        return ApiRes.SUCCESS;
    }

	
    @ApiOperation("删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @RequiresPermissions("whospital:delete")
    @ResponseBody
    public ApiRes delete(Integer[] ids) {
        wHospitalService.deleteBatch(ids);
        return ApiRes.SUCCESS;
    }


    /**
     * 获取医院列表
     * @return
     */
    @ApiOperation("获取医院列表")
    @RequestMapping(value = "/selectHospital", method = RequestMethod.POST)
    public @ResponseBody
    ApiRes selectHospital(WHospitalEntity bean, @ModelAttribute("pageParam")PageParam pageParam){
        List<WHospitalEntity> list = wHospitalService.queryList(bean, pageParam);

        for (WHospitalEntity wHospital: list
                ) {
            wHospital.setId(Integer.valueOf(wHospital.getHospitalCode()));
        }
        int total = wHospitalService.queryTotal(bean);
        return new ApiRes(true,list,null,String.valueOf(total));
    }
}
